package com.cn.jdia.dc.utils;

import java.util.Properties;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;

public class SSHUtils {

	private static int DEFAULT_SSH_PORT = 22;
	private static int DEFAULT_TIMEOUT=60000000;

	public static int sshConnect(String host,String user,String pwd) {
		JSch jsch = new JSch();
		try {
			Session session=jsch.getSession(user, host, DEFAULT_SSH_PORT);
			
			session.setPassword(pwd);
			session.setTimeout(DEFAULT_TIMEOUT);
			
			Properties config = new Properties();
			config.put("StrictHostKeyChecking", "no");
			session.setConfig(config);
			
			session.connect();
			session.disconnect();
			
		} catch (JSchException e) {
			e.printStackTrace();
			return -1;
		}

		return 0;
	}
	
}
